package com.xl.exercise;

import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        //完成评委打分案例
        System.out.println("请输入评委的个数：");
        int number = new Scanner(System.in).nextInt();
        double score = getScore(number);
        System.out.println("当前选手得分：" + score);
    }

    public static double getScore(int number) {
        //定义一个动态初始化的数组，负责后期存入评委打分
        double[] scores = new double[number];
        //遍历数组的每个位置，依次录入评委的分数
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < number; i++) {
            System.out.println("请您录入第"+(i+1)+"个评委的分数：");
            scores[i] = scanner.nextDouble();
        }
        double sum = 0;
        double max = scores[0];
        double min = scores[0];
        //遍历数组找出这些数据
        for (int i = 0; i < scores.length; i++) {
            double score = scores[i];
            sum += score;
            if (score > max) {
                max = score;
            }
            if (score < min) {
                min = score;
            }
        }
        //去掉最高分和最低分
        sum -= max;
        sum -= min;
        return sum / (number - 2);
    }
}
